package Array;

/**
 * 合并两个有序数组
 * <a>https://leetcode.cn/problems/merge-sorted-array/</a>
 */
public class Array01 {

    public void merge(int[] nums1, int m, int[] nums2, int n) {

        int right = 0, left = 0;
        int[] result = new int[m + n];
        int cur;
        while (left < m || right < n) {
            if (left == m){
                cur = nums2[right++];
            } else if (right ==n){
                cur = nums1[left++];
            }else if (nums1[left]<nums2[right]){
                cur = nums1[left++];
            }else {
                cur = nums2[right++];
            }
            result[right+left-1]=cur;
        }
        for (int i =0;i<m+n;i++){
            nums1[i]=result[i];
        }
    }

}
